<template>
    <div class="components-container">
    <!-- 存入 -->
    <sweet-modal ref="dialogIn" class="dialog" :sweetModalMaxWidth="pageWidth">
        <h3>{{title}}</h3>
        
        <div>
            <div class="layui-form-item">
                    <label class="layui-form-label">证件号码</label>
                <div class="layui-input-inline">
                    <el-input v-model="deaddata.JpmCardnoEquals" placeholder="请输入证件号码" @keyup.native="SeachDead($event)"></el-input>
                </div>       
                <el-button type="primary" @click="openRegCheck">选取逝者</el-button>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">逝者姓名</label>
                    <div class="layui-input-inline">
                        <el-input v-model="deaddata.deadName" readonly></el-input>
                    </div>
                </div>    
               
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">联系人</label>
                    <div class="layui-input-inline">
                        <el-input v-model="deaddata.linkMan" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">联系电话</label>
                    <div class="layui-input-inline">
                        <el-input v-model="deaddata.linkTel" readonly></el-input>
                    </div>
                </div>
            </div>
                 <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">已发送短信</label>
                    <el-radio-group  class="layui-input-inline" v-model="radio" >
                         <el-radio  label="1">是</el-radio>
                         <el-radio  label="0">否</el-radio>
                    </el-radio-group>
                </div>
               <div class="layui-inline">
                <label class="layui-form-label">存入时间</label>
                <div class="layui-input-inline">
                    <el-date-picker v-date v-model="ichdataExtend.saveDates" type="datetime" class="longtext" placeholder="选择日期时间" small> </el-date-picker>
                </div>
                </div>
            </div>

                  <div class="layui-form-item">
                      <label class="layui-form-label">办结结果</label>
                            <div class="layui-input-inline" style="width:77.5%;margin-bottom: 10px;">
                    <el-input type="textarea" medium :autosize="{ minRows: 2, maxRows: 4}"  placeholder="请输入内容" v-model="deaddata.textarea" maxlength="140" show-word-limit ></el-input>
                            </div>
             
            </div>
        
        </div>
        <div class="layui-form-item btnCenter">
            <el-button @click="closeDialog">取消</el-button>
            <el-button type="primary" @click="submitAdd">提交</el-button>
        </div>
    </sweet-modal>
    <!-- 逝者选择 -->
    <sweet-modal ref="deadSelect" class="dialog">
        <h3>逝者选择</h3>
        <div class="layui-form-item">
            <label class="layui-form-label">选取逝者</label>
            <div class="layui-input-inline">
                <el-input v-date  v-model="deaddata.Names"  @keyup.native="getRegData($event)"></el-input>
            </div>
        </div>
        <div style="height:400px;max-height:400px;overflow:auto;">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>业务编号</th>
                        <th>逝者姓名</th>
                        <th>联系人</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="item in regCheckList" :key="item.value">                       
                        <td>{{item.JPMCARDNO}}</td>
                        <td>{{item.JPMNAME}}</td>
                        <td>{{item.JPMLINKMAN}}</td>                     
                        <td><button @click="getDead(item)" class="layui-btn layui-btn-normal">选择</button></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </sweet-modal>

  
   
    </div>

</template>

<style  rel="stylesheet/scss" lang="scss" scoped>
.el-radio {
  margin: 10px 25px;
}
</style>
<script>
const INFO = "详情";
import apiBase from "@/api/apiBase.js";
import sweetModal from "@/components/sweetModal";
import {
  formatDate,
  timeStringToDate,
  dateStringToDate
} from "@/utils/date.js";
export default {
  data() {
    return {
      text: "",

      radio: true,

      ichData: {
        REGSEXs: null
      },
      ichdataExtend: {
        ichEndDates: null,
        saveDates: null
      },
      ichDataEexend: {
        staTime: null,
        endTime: null
      },
      deaddata: {
        JpmCardnoEquals: null,
        deadName: null,
        textarea: ""
      },

      pageWidth: 700,
      maxHeight: 500,
      title: null,
      order: null,
      icelist: [],
      regCheckDate: null,
      regCheckList: [],
      QueryDriver: []
    };
  },
  methods: {
    open(order, id) {
      this.order = order;
      this.geticenotuse();
      this.dataRepeat();
      switch (this.order) {
        case "新增":
          this.title = "办结新增";
          this.$refs.dialogIn.open();
          break;
        default:
      }
    },

    //获取火化登记数据
    getRegData(ev) {
      if (ev.keyCode === 13) {
        this.IsEnter === true;
        let data = {
          data: {
            JpmNameEquals: this.deaddata.Names
          }
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().JointRegConclude.QueryJointReg,
          res => {
            this.regCheckList = res.data.content.OutData;
          }
        );
      } else {
        if (this.IsEnter === true) {
          this.deaddata.JpmCardnoEquals = "";
        }
      }
    },
    dataRepeat() {
      this.deaddata.JpmCardnoEquals = null;
      this.deaddata.deadid = null;
      this.deaddata.deadName = null;
      this.deaddata.deaddate = null;
      this.deaddata.linkMan = null;
      this.deaddata.linkTel = null;
      this.radio = true;
      this.deaddata.textarea = null;
      this.ichdataExtend = {};
    },
    //点击选择
    getDead(item) {
      this.deaddata.JpmCardnoEquals = item.JPMCARDNO;
      this.deaddata.deadName = item.JPMNAME;
      this.deaddata.Names = item.JPMNAME;
      this.deaddata.deaddate = item.REGDEATHDATE;
      this.deaddata.linkMan = item.JPMLINKMAN;
      this.deaddata.linkTel = item.JPMLINKPHONE;
      this.deaddata.deadid = item.JPMID;
      this.$refs.deadSelect.close();
    },
    SeachDead(ev) {
      if (ev.keyCode === 13) {
        this.IsEnter = true;
        let data = {
          data: {
            JpmCardnoEquals: this.deaddata.JpmCardnoEquals
          }
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().JointRegConclude.QueryJointReg,
          res => {
            if (res.data.content.OutData.length != 0) {
              this.deaddata.JpmCardnoEquals = res.data.content.OutData[0].JPMCARDNO;
              this.deaddata.deadName = res.data.content.OutData[0].JPMNAME;
              this.deaddata.linkMan = res.data.content.OutData[0].JPMLINKMAN;
              this.deaddata.linkTel = res.data.content.OutData[0].JPMLINKPHONE;
              this.deaddata.deadid = res.data.content.OutData[0].JPMID;
            } else alert("身份证号码不正确请选择逝者");
          }
        );
      } else {
        if (this.IsEnter === true) {
          this.deaddata.JpmCardnoEquals = "";
          this.IsEnter = false;
        }
      }
    },
    geticenotuse(id) {
      apiBase.DoService(
        { ICEID: id },
        apiBase.getApiAdress().IceUse.QueryIceBynotuse,
        res => {
          this.icelist = res.data.content;
        }
      );
    },
    submitAdd() {
      //确定存入
      let data = {
        //请求体
        JPBJPMID: this.deaddata.deadid, //id
        JPBISSENDMSG: this.radio,
        JPBDESC: this.deaddata.textarea, //逝者编号
        JPBDATE: formatDate(this.ichdataExtend.saveDates, "yyyyMMdd"), //存入时间
        JPBTIME: formatDate(this.ichdataExtend.saveDates, "hhmmss") //存入日期
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().JointRegConclude.CreateJointRegConclude,
        res => {
          // this.cancel();
          this.$refs.dialogIn.close();
          this.$message.success("存入成功");
           this.refreshData();
        }
      );
    },

    refreshData() {
      this.$emit("refreshData");
    },
    //打开逝者选取
    openRegCheck() {
      this.regCheckDate = new Date();

      this.$refs.deadSelect.open();
    },
    closeDialog() {
      this.$refs.dialogIn.close();
    },

    //登记详情
    dataInfo(id) {
      let data = {
        ICHID: id
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().JointRegConclude.QueryJointReg,
        res => {
          this.ichData = res.data.content;
          this.ichDataEexend.staTime = timeStringToDate(
            this.ichData.ICHBEGTIME,
            this.ichData.ICHBEGDATE
          );
          this.ichDataEexend.endTime = timeStringToDate(
            this.ichData.ICHENDTIME,
            this.ichData.ICHENDDATE
          );
        }
      );
    }
  },
  components: {
    sweetModal
  },

  created() {
    apiBase.DoService({}, apiBase.getApiAdress().Staff.QueryDriver, res => {
      this.QueryDriver = res.data.content;
    });
  }
};
</script>

